<?php

namespace app\mingteng\controller;

use think\Db;

class Lockconfiguration extends Base
{
    protected $row = null;
    public function __construct()
    {
        $row = Db::name('lock_screen_configuration')->where('id',1)->find();
        if(empty($row)){
            $rowArray = [
                'big_details'=>'',
                'min_details'=>'',
                'default_img'=>'',
                'before_img'=>'',
                'after_img'=>'',
                'createtime'=>time(),
                'updatetime'=>time(),
            ];
            Db::name('lock_screen_configuration')->insert($rowArray);
            $row = Db::name('lock_screen_configuration')->where('id',1)->find();
        }
        $this->row = $row;
        parent::__construct();
    }

    public function index()
    {
        if($this->request->isAjax()){
            $data = $this->request->param();
            $data['updatetime'] = time();
            $res = Db::name('lock_screen_configuration')->where('id',1)->update($data);
            if(!$res){
                return $this->error("修改失败");
            }
            return $this->success('修改成功');
        }
        $this->assign('row',$this->row);
        return $this->fetch();
    }
}